<?php

class Register {
	
	public static $plugins = Array ();
	public static $extensions  = Array ();
	public static $startPluginList = Array ();
	public static $controllers = array ();
	public static $pluginLead;
	public static $defaultController;
	public static $controllerName;
	
	/**
	 * Get default controller<br>
	 * When not find the corresponding controller will load controller set here. 
	 *
	 * @return String Controller name
	 */
	public function getDefaultController(){
		return Register::$defaultController;
	}
	
	/**
	 * Set default controller<br>
	 *
	 * @param String default controller name
	 */
	public function setDefaultController($controllerName){
		Register::$defaultController = $controllerName;
	}
	
	/**
	 * Get extension points
	 *
	 * @param extension point name
	 * @param plugin id
	 * @return array
	 */
	public function getExtension($name, $plugin=null){
		if($plugin==null){
			$plugin = Runtime::getPluginId();
		}
		if( isset(Register::$extensions[$name.'@'.$plugin]) ){
			return Register::$extensions[$name.'@'.$plugin];
		}
		return null; 
	}

	/**
	 * add execute controller
	 *
	 * @param String controller name
	 * @param String plugin id
	 */
	public static function addControllers($controller, $pluginId) {
		array_push(Register::$controllers, $controller);
		Register::$pluginLead = $pluginId;
	}
	
	/**
	 * Get controller name
	 *
	 * @return String
	 */
	public static function getControllerName() {
		return Register::$controllerName;
	}
	
	/**
	 * Set controller name
	 *
	 * @param String $name
	 */
	public static function setControllerName($name) {
		Register::$controllerName = $name;
	}
	
	/**
	 * Get all of execute controllers
	 *
	 * @return array
	 */
	public static function getControllers() {
		return Register::$controllers;
	}

	/**
	 * Get plugins
	 *
	 * @param String plugin id
	 * @return array
	 */
	public function getPlugins($pluginId=null){
		if( $pluginId!=null && isset(Register::$plugins[$pluginId]) ){
			return Register::$plugins[$pluginId];
		}else if( $pluginId==null ){
			return Register::$plugins;
		}
		return null;
	}
	
}

?>